package org.skyfree.ghyll.tcard.action;

import org.eclipse.jface.viewers.TreeViewer;
import org.eclipse.swt.graphics.Image;
import org.skyfree.ghyll.tcard.core.ITCard;

public class UpDownMenuItemAction extends AbstractMenuItemAction {

	public UpDownMenuItemAction(boolean up,int style, String text, int Accelerator,
			Image image, TreeViewer treeViewer) {
		super(style, text, Accelerator, image, treeViewer);
		this.up = up;
	}

	private boolean up;

	public boolean isEnable()
	{
		ITCard card = (ITCard) this.item.getData();
		ITCard parent = card.getParent();
		if(parent==null)return false;
		int index = parent.getSubTCard().indexOf(card);
		if(index==0)
		{
			if(up)return false;
		}
		if(index==(parent.getSubTCard().size()-1))
		{
			if(!up)return false;
		}
		return true;
	}

	
	@Override
	public void execute(Object object) throws Exception {
		ITCard card = (ITCard) this.item.getData();
		ITCard parent = card.getParent();
		parent.moveAround(up,card);
		
	}
}
